//
//  TextHeightTool.m
//  Player
//
//  Created by muji on 16/1/6.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "MujiDubTextHeightTool.h"

@implementation MujiDubTextHeightTool

//计算文字Size
+ (CGSize)getHeightWithString:(NSString *)text width:(CGFloat)width
{
    CGSize size = [text boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:15]} context:NULL].size;
    
    return size;
}

+ (CGSize)getHeightWithString:(NSString *)text width:(CGFloat)width font:(int)font
{
    CGSize size = [text boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:font]} context:NULL].size;
    
    return size;
    
    
    
    
}

+ (CGFloat)getStringHeightWithStr:(NSString *)text width:(CGFloat)width font:(int)font
{
    
    /*
     int WordCount=(kScreenWidth-40 - 40)/13;
     //下面是使用字体的长度(就是字体的个数)/上面计算出的每行存放字体的个数，算出一共有多少行
     CGFloat heightCount= teststr.length/WordCount;
     //heightCount*15  下面我们就是通过上一步计算出的 行数*字体的高度，计算出label最终的展示高度
     //[label setFrame:CGRectMake(label.frame.origin.x, 0, label.frame.size.width,heightCount*15 )];
     //label.numberOfLines = 0;
     
     CGSize labelSize = [teststr sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(kScreenWidth - 40, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];    //核心代码
     
     NSLog(@"-fsdfffff------%f", (heightCount +1)* 20 );
     */
    
    
    
    int WordCount = width/13;
    //下面是使用字体的长度(就是字体的个数)/上面计算出的每行存放字体的个数，算出一共有多少行
    CGFloat heightCount= text.length/WordCount;
    //heightCount*15  下面我们就是通过上一步计算出的 行数*字体的高度，计算出label最终的展示高度
    
    return (heightCount + 1)*20;

//    return CGSizeMake(width, (heightCount + 1)*20);

}

+ (CGFloat)getStringHeightWithString:(NSString *)text width:(CGFloat)width font:(int)font
{
    
    
    CGRect frame = [text boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:font]} context:NULL];
    
    return frame.size.height;
}

+ (CGFloat)getStringWidthWithString:(NSString *)text height:(CGFloat)height font:(int)font
{
    
    
    CGRect frame = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:font]} context:NULL];
    
    return frame.size.width;
}



@end
